package heven.holt.wan.android.listener

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.google.android.material.tabs.TabLayout
import heven.holt.wan.android.R

class HomeTabSelectedListener : TabLayout.OnTabSelectedListener {
    override fun onTabSelected(tab: TabLayout.Tab) {
        setColorFilter(tab.customView, android.R.color.white)
    }

    override fun onTabUnselected(tab: TabLayout.Tab) {
        setColorFilter(tab.customView, R.color.gray_alpha)
    }

    override fun onTabReselected(tab: TabLayout.Tab) {
    }

    private fun setColorFilter(view: View?, id: Int) {
        view?.apply {
            val icon = findViewById<ImageView>(R.id.icon)
            val name = findViewById<TextView>(R.id.name)
            icon.setColorFilter(ContextCompat.getColor(icon.context, id))
            name.setTextColor(ContextCompat.getColor(name.context, id))
        }
    }
}